﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using HospitalSystem.Core;
namespace HospitalSystem
{
    public partial class ChildDetails : System.Web.UI.Page
    {
        private show_Image _showimage;
        protected void Page_Load(object sender, EventArgs e)
        {

          
            _showimage = new show_Image();

            _showimage.show_Images(cid_label, Image1);

            string CIDstring = Request.QueryString["CID"];


            //ถ้ามีคิวรี่สติง ให้คิวรี่โชว์ตามคิวรี่
            if (CIDstring != null)
            {
                showlistfamily2();
                sendsession();
                showsession();
                //showlistfamily2();
                showlistfamily2();


            }

            else
            //ถ้า ไม่มีคิวรี่สติง( เข้าแค่ ChildDetails.aspx   ธรรมดา จะถือเอา sesson CID มาคิวรี่โชว์)  ทำเพื่อสำหรับหน้ากลับข้อมูลส่วนตัวจะได้กลับไปที่  ChildDetails.aspx ได้

            {
                showchild();
            }

        }


        protected void sendsession()
        {
            Session["CID"] = Request.QueryString["CID"];
            Session["FirstName"] = Name.Text;
            Session["LastName"] = LastName.Text;
   

        }

        protected void showchild()
        {

            String ShowValue = (string)Session["CID"];
            cid_label.Text = ShowValue;
            String ShowValue2 = (string)Session["LastName"];
            lname.Text = ShowValue2;

            String ShowValue3 = (string)Session["FirstName"];
            fname.Text = ShowValue3;
            
            
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection scon = new SqlConnection(constr);
                SqlCommand cmd = new SqlCommand("SELECT Gender,BloodType,CID,Title,FirstName,LastName,DOB,Nation,Race,Religion,Foreigner,LiveHomeStatus,EducationStatus,LiveStreetAddress,LiveStreetName,Livetumbon,LiveCity,LiveProvince,LivePostcode,CensusStreetAddress,CensusStreetName,Censustumbon,CensusCity,CensusProvince,CensusPostcode,HomePhone,Mobile,RecordedStaffID,LiveMoveInDate,LiveMoveOutDate,CensusMoveInDate,CensusMoveOutDate,LiveMoveOutReason,CensusMoveOutReason,CensusHouseMoo,CensusHouseName,CensusHousesoy,LiveHouseMoo,LiveHouseName,LiveHousesoy,Livetumbon FROM [Person] where CID=@CID", scon);
                cmd.Parameters.AddWithValue("@CID", cid_label.Text);

                scon.Open();
                SqlDataReader reader2 = cmd.ExecuteReader();


                if (reader2.Read())
                {
                    Name.Text = reader2["FirstName"].ToString();
                    LastName.Text = reader2["LastName"].ToString();
                    CID.Text = reader2["CID"].ToString();
                    BloodType.Text = reader2["BloodType"].ToString();
                    Gender.Text = reader2["Gender"].ToString();
                    //Titles.Text = reader2["Title"].ToString();
                    Race.Text = reader2["Race"].ToString();
                    Religion.Text = reader2["Religion"].ToString();
                    LiveHouseNumber.Text = reader2["LiveStreetAddress"].ToString();
                    LiveHouseName.Text = reader2["LiveHouseName"].ToString();
                    LiveHouseMoo.Text = reader2["LiveHouseMoo"].ToString();
                    LiveHousesoy.Text = reader2["LiveHousesoy"].ToString();
                    Livetambon.Text = reader2["Livetumbon"].ToString();
                    LiveCity.Text = reader2["LiveCity"].ToString();
                    LiveProvince.Text = reader2["LiveProvince"].ToString();
                    LivePostcode.Text = reader2["LivePostcode"].ToString();
                    CensusHouseNumber.Text = reader2["CensusStreetAddress"].ToString();
                    CensusHouseName.Text = reader2["CensusHouseName"].ToString();
                    CensusHouseMoo.Text = reader2["CensusHouseMoo"].ToString();
                    CensusHousesoy.Text = reader2["CensusHousesoy"].ToString();
                    Censustambon.Text = reader2["Censustumbon"].ToString();
                    CensusCity.Text = reader2["CensusCity"].ToString();
                    CensusProvince.Text = reader2["CensusProvince"].ToString();
                    CensusPostcode.Text = reader2["CensusPostcode"].ToString();

                    LastNation.Text = reader2["Nation"].ToString();
                    CensusStreetName.Text = reader2["CensusStreetName"].ToString();
                    LiveStreetName.Text = reader2["LiveStreetName"].ToString();
                }
                else
                {

                }
                scon.Close();
                reader2.Close();
            }


        





        protected void showsession()
        {
           
            
            String ShowValue = (string)Session["CID"];
            cid_label.Text = ShowValue;
            String ShowValue2 = (string)Session["LastName"];
            lname.Text = ShowValue2;

            String ShowValue3 = (string)Session["FirstName"];
            fname.Text = ShowValue3;
        }

        public void showlistfamily2()
        {


            string CIDstring = Request.QueryString["CID"];
            //if (CIDstring != null)
            //{
                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection scon = new SqlConnection(constr);
                SqlCommand cmd = new SqlCommand("SELECT Gender,BloodType,CID,Title,FirstName,LastName,DOB,Nation,Race,Religion,Foreigner,LiveHomeStatus,EducationStatus,LiveStreetAddress,LiveStreetName,Livetumbon,LiveCity,LiveProvince,LivePostcode,CensusStreetAddress,CensusStreetName,Censustumbon,CensusCity,CensusProvince,CensusPostcode,HomePhone,Mobile,RecordedStaffID,LiveMoveInDate,LiveMoveOutDate,CensusMoveInDate,CensusMoveOutDate,LiveMoveOutReason,CensusMoveOutReason,CensusHouseMoo,CensusHouseName,CensusHousesoy,LiveHouseMoo,LiveHouseName,LiveHousesoy,Livetumbon FROM [Person] where CID=@CID", scon);
                cmd.Parameters.AddWithValue("@CID", CIDstring);

                scon.Open();
                SqlDataReader reader2 = cmd.ExecuteReader();


                if (reader2.Read())
                {
                    Name.Text = reader2["FirstName"].ToString();
                    LastName.Text = reader2["LastName"].ToString();
                    CID.Text = reader2["CID"].ToString();
                    BloodType.Text = reader2["BloodType"].ToString();
                    Gender.Text = reader2["Gender"].ToString();
                    //Titles.Text = reader2["Title"].ToString();
                    Race.Text = reader2["Race"].ToString();
                    Religion.Text = reader2["Religion"].ToString();
                    LiveHouseNumber.Text = reader2["LiveStreetAddress"].ToString();
                    LiveHouseName.Text = reader2["LiveHouseName"].ToString();
                    LiveHouseMoo.Text = reader2["LiveHouseMoo"].ToString();
                    LiveHousesoy.Text = reader2["LiveHousesoy"].ToString();
                    Livetambon.Text = reader2["Livetumbon"].ToString();
                    LiveCity.Text = reader2["LiveCity"].ToString();
                    LiveProvince.Text = reader2["LiveProvince"].ToString();
                    LivePostcode.Text = reader2["LivePostcode"].ToString();
                    CensusHouseNumber.Text = reader2["CensusStreetAddress"].ToString();
                    CensusHouseName.Text = reader2["CensusHouseName"].ToString();
                    CensusHouseMoo.Text = reader2["CensusHouseMoo"].ToString();
                    CensusHousesoy.Text = reader2["CensusHousesoy"].ToString();
                    Censustambon.Text = reader2["Censustumbon"].ToString();
                    CensusCity.Text = reader2["CensusCity"].ToString();
                    CensusProvince.Text = reader2["CensusProvince"].ToString();
                    CensusPostcode.Text = reader2["CensusPostcode"].ToString();

                    LastNation.Text = reader2["Nation"].ToString();
                    CensusStreetName.Text = reader2["CensusStreetName"].ToString();
                    LiveStreetName.Text = reader2["LiveStreetName"].ToString();
                }
                else
                {

                }
                scon.Close();
                reader2.Close();
            //}


                            
        }















        protected void edit_Click(object sender, EventArgs e)
        {
            sendsession2();
        }

        protected void sendsession2()
        {
            Session["fCID"] = CID.Text;



            Response.Redirect("~/familyedit.aspx");


        }
    }
}